//
//  UserView.m
//  吃货·上海
//
//  Created by 濮亚军 on 15/11/25.
//  Copyright © 2015年 濮亚军. All rights reserved.
//

#import "UserView.h"
#import "MineView.h"
#import "UIImageView+WebCache.h"
#import <BmobSDK/Bmob.h>
#import "MineModel.h"
@interface UserView()

//头像区 背景
@property(nonatomic, strong)UIImageView *bgImageView;


@property(nonatomic, strong)UIView *labelView;

@property(nonatomic, strong)UIView *mineBgView;

//吃货背景图

@property(nonatomic, strong)UIImageView *chiHuoImageView;
@end


@implementation UserView

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        self.backgroundColor = kBarColor;
        //设置头像区的背景
        CGFloat n = KScreenWidth / 375;
        CGFloat height = n * 250;
        
        self.bgImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, height)];
        self.bgImageView.image = [UIImage imageNamed:@"foodie"];
        //self.bgImageView.backgroundColor = [UIColor redColor];
        [self addSubview:_bgImageView];
        
        //头像
        CGFloat x = KScreenWidth  / 8 * 3;
        self.iconImageView = [[UIImageView alloc]initWithFrame:CGRectMake(x, 5, KScreenWidth / 4, KScreenWidth / 4)];
        //self.iconImageView.backgroundColor = [UIColor redColor];
        //self.iconImageView.image = [UIImage imageNamed:@"textIcon.jpg"];
        BmobUser *bUser = [BmobUser getCurrentUser];
        MineModel *mineModel = [[MineModel alloc]initWithUserModel:bUser];
        [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:mineModel.userImageStr] placeholderImage:[UIImage imageNamed:@"textIcon.jpg"]];
        self.iconImageView.layer.masksToBounds = YES;
        [self.iconImageView.layer setCornerRadius:KScreenWidth / 8];
        [self.bgImageView addSubview:_iconImageView];
        
        //登录注册按钮
        self.labelView = [[UIView alloc]initWithFrame:CGRectMake(0, height - 50 * n, KScreenWidth, 50 * n)];
        //self.labelView.backgroundColor = [UIColor redColor];
        [self addSubview:_labelView];
        
        //登录按钮
        self.loginImageView = [[UIImageView alloc]initWithFrame:CGRectMake(70 * n, 10, 80 * n, 35 * n)];
        self.loginImageView.image = [UIImage imageNamed:@"loginUserView"];
        self.loginImageView.userInteractionEnabled = YES;
        self.loginImageView.layer.masksToBounds = YES;
        [self.loginImageView.layer setCornerRadius:8];
        //self.loginImageView.backgroundColor = [UIColor redColor];
        [self.labelView addSubview:_loginImageView];
        
        //注册按钮
        self.registerImageView = [[UIImageView alloc]initWithFrame:CGRectMake( KScreenWidth - 150 * n, 10, 80 * n, 35 * n)];
        self.registerImageView.image = [UIImage imageNamed:@"register"];
        self.registerImageView.userInteractionEnabled = YES;
        self.registerImageView.layer.masksToBounds = YES;
        [self.registerImageView.layer setCornerRadius:8];
        //self.registerImageView.backgroundColor = [UIColor redColor];
        [self.labelView addSubview:_registerImageView];
        
        //应用背景
        //适应屏幕的宽高
        CGFloat appWidth = KScreenWidth / 4;
        CGFloat width = 375 / 4;
        CGFloat num = appWidth / width ;
        NSLog(@"num == %f", num);
        self.mineBgView = [[UIView alloc]initWithFrame:CGRectMake(0, height + 10, KScreenWidth, 80 * n)];
        //self.mineBgView.userInteractionEnabled = NO;
        [self addSubview:_mineBgView];
        
        UILabel *lineLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, 1)];
        lineLabel.backgroundColor = [UIColor grayColor];
        lineLabel.alpha = 0.4;
        [self.mineBgView addSubview:lineLabel];
        
        UILabel *bottomLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, n * 80, KScreenWidth, 1)];
        bottomLabel.backgroundColor = [UIColor grayColor];
        bottomLabel.alpha = 0.4;
        [self.mineBgView addSubview:bottomLabel];
        
        
        //应用按钮
        //我的菜谱
        self.mineMenuView = [[MineView alloc]initWithFrame:CGRectMake(0, 0, appWidth, n * 80) image:[UIImage imageNamed:@"mineMenu"] title:@"我的菜谱"];
        //self.mineMenuView.backgroundColor = [UIColor redColor];
        [self.mineBgView addSubview:_mineMenuView];
        
        //我的发布
        self.minePushView = [[MineView alloc]initWithFrame:CGRectMake(appWidth, 0, appWidth, n * 80) image:[UIImage imageNamed:@"minePush"] title:@"我的发布"];
        [self.mineBgView addSubview:_minePushView];
        
        //我的主页
        self.mineHPView = [[MineView alloc]initWithFrame:CGRectMake(2 * appWidth, 0, appWidth, n * 80) image:[UIImage imageNamed:@"mineHP"] title:@"我的主页"];
        [self.mineBgView addSubview:_mineHPView];
        
        //我的设置
        self.mineSettingsView = [[MineView alloc]initWithFrame:CGRectMake(3 * appWidth, 0, appWidth, n * 80) image:[UIImage imageNamed:@"mineSettings"] title:@"我的设置"];
        [self.mineBgView addSubview:_mineSettingsView];
        
        //吃货背景
        CGFloat chiHuoX = (KScreenWidth - 236 * n) / 2;
        //CGFloat chiHuoY = (frame.size.height - 170 * n);
        //NSLog(@"KScreenHeight - self.mineBgView.frame.origin.y == %f",KScreenHeight - self.mineBgView.frame.origin.y - 128 - self.mineBgView.frame.size.height);
        self.chiHuoImageView = [[UIImageView alloc]initWithFrame:CGRectMake(chiHuoX, self.mineBgView.frame.origin.y + self.mineBgView.frame.size.height + 10 , 236 * n, 50 *n)];
        self.chiHuoImageView.image = [UIImage imageNamed:@"chihuo"];
        [self addSubview:_chiHuoImageView];
        
    }
    return self;
}

@end
